#include "quad.h"
#include <iostream>
#include <stdlib.h>
#include <cmath>
using namespace std;

void Quad::glDraw()
{
//check if face is completely created
    if(vertex.size() != 6)
    {
        std::cout<<vertex.size()<<std::endl;
        std::cout<<"**Error: Num of points doesn't match a Quad\n";
        exit(0);
    }

    glColor3f(vertex[5][0], vertex[5][1], vertex[5][2]);    //color
    glBegin(GL_QUADS);                                      
        glNormal3f(vertex[4][0], vertex[4][1], vertex[4][2]);   //set normal vector
        for(int i = 0; i < 4; i++)
        {
            glVertex3f(vertex[i][0], vertex[i][1], vertex[i][2]);
        }
    glEnd();
}


void Quad::rotateX(GLfloat ang)
{
    GLfloat y, z;
    if(vertex.size() != 6)
    {
        std::cout<<"**Error: Num of points doesn't match a Quad\n";
        exit(0);
    }

    std::vector<GLfloat> newPoint;    //points buffer
    for(int i = 0; i < 5; i++)
    {
        //store values
        y = vertex[i][1];
        z = vertex[i][2];
        //transform
        vertex[i][1] = y * cos(ang) - z * sin(ang);
        vertex[i][2] = y * sin(ang) + z * cos(ang);
    }
}

void Quad::rotateY(GLfloat ang)
{
    GLfloat x, z;
    if(vertex.size() != 6)
    {
        std::cout<<"Num of points didn't match a Quad\n";
        exit(0);
    }

    GLfloat newPoint[3];    //points buffer
    for(int i = 0; i < 5; i++)
    {
        
        //store values
        x = vertex[i][0];
        z = vertex[i][2];
        //transform
        vertex[i][0] = z * sin(ang) + x * cos(ang);
        vertex[i][2] = z * cos(ang) - x * sin(ang);
    }
}

void Quad::rotateZ(GLfloat ang)
{
    GLfloat x, y;
    if(vertex.size() != 6)
    {
        std::cout<<"Num of points didn't match a Quad\n";
        exit(0);
    }

    GLfloat newPoint[3];    //points buffer
    for(int i = 0; i < 5; i++)
    {
        //store values
        x = vertex[i][0];
        y = vertex[i][1];
        //transform
        vertex[i][0] = x * cos(ang) - y * sin(ang);
        vertex[i][1] = x * sin(ang) + y * cos(ang);
    }
}

